package com.nantong.admin.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.nantong.admin.annotation.PermissionRegister;
import com.nantong.admin.domain.model.request.salesorder.SalesStatisticsSearch;
import com.nantong.admin.domain.model.response.salesorder.SalesStatisticsVo;
import com.nantong.admin.service.ISalesOrderService;
import com.nantong.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.web.bind.annotation.*;

/**
 * 销售统计Controller
 */
@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/system/sales-statistics")
@PermissionRegister(
    name = "销售统计",
    key = "system:sales-statistics",
    type = 2,  // 2=菜单
    path = "sales-statistics",
    component = "/views/SalesOrder/SalesStatisticsView.vue",
    icon = "bar-chart",
    sortOrder = 4,
    parentKey = "system"  // 父菜单是system
)
@Tag(name = "销售统计", description = "销售统计相关接口")
public class SalesStatisticsController {

    private final ISalesOrderService salesOrderService;

    /**
     * 销售统计
     */
    @GetMapping
    @Operation(summary = "销售统计", description = "获取销售统计数据")
    @SaCheckPermission("system:sales-statistics:query")
    @PermissionRegister(
            name = "销售统计查询",
            key = "system:sales-statistics:query",
            type = 3,  // 3=按钮
            remark = "查询销售统计数据"
    )
    public R<SalesStatisticsVo> statistics(SalesStatisticsSearch search) {
        SalesStatisticsVo statistics = salesOrderService.getSalesStatistics(search);
        return R.ok(statistics);
    }
}

